package com.cn.aam.checaiduo.ui.me.helper;

import android.text.TextUtils;

import com.cn.aam.checaiduo.bean.me.VoucherB;

import java.util.Collections;
import java.util.Comparator;

/**
 * monker on 2017/6/13.
 */

public class MeHelper {

    private static final String VOUCHER_HAS_EXPIRED = "1";
    private static final String VOUCHER_HAS_USED = "1";

    public static final String VOUCHER_CAN_USED = "1";
    public static final String VOUCHER_CANNOT_USED = "0";


    /**
     * 时间：2017/6/13
     * 描述：理财券是否可用
     */
    public static String voucherCanUse(String user, String expired) {
        if (TextUtils.equals(user, VOUCHER_HAS_USED) || TextUtils.equals(expired, VOUCHER_HAS_EXPIRED)) {
            return VOUCHER_CANNOT_USED;
        }
        return VOUCHER_CAN_USED;
    }

    public static void sortList(final VoucherB voucherB) {
        if (voucherB==null) return ;
        Collections.sort(voucherB.getCash_coupon(), new Comparator<VoucherB.CashCouponBean>() {
            @Override
            public int compare(VoucherB.CashCouponBean o1, VoucherB.CashCouponBean o2) {
                String canUse1 = voucherCanUse(o1.getUsed(), o1.getExpired());
                String canUse2 = voucherCanUse(o2.getUsed(), o2.getExpired());
                if (canUse1.compareTo(canUse2) < 0) {
                    return 1;
                } else if (canUse1.compareTo(canUse2) == 0) {
                    return 0;
                }
                return -1;
            }


        });

        Collections.sort(voucherB.getRate_coupon(), new Comparator<VoucherB.RateCouponBean>() {
            @Override
            public int compare(VoucherB.RateCouponBean o1, VoucherB.RateCouponBean o2) {
                String canUse1 = voucherCanUse(o1.getUsed(), o1.getExpired());
                String canUse2 = voucherCanUse(o2.getUsed(), o2.getExpired());
                if (canUse1.compareTo(canUse2) < 0) {
                    return 1;
                } else if (canUse1.compareTo(canUse2) == 0) {
                    return 0;
                }
                return -1;
            }

        });

    }


}


